package stu.day25_day32.day26;
import stu.day25_day32.day25.all.*;

public class hw3 {

    int max = Integer.MIN_VALUE;
    public int maxPathSum(TreeNode root) {
        path(root);
        return max;
    }

    public int path(TreeNode node){
        if(node==null){
            return 0;
        }
        int left = path(node.left);
        int right = path(node.right);

        int num = Math.max(node.val,node.val+left+right);
        num = Math.max(num,node.val+left);
        num = Math.max(num,node.val+right);

        max = Math.max(max,num);

        int v = Math.max(node.val, node.val+left);
        v = Math.max(v,node.val+right);

        return v;
    }


}
